{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们当然可以使用当前路径拼接Package的层层路进行进行定位File位置。但是也可以使用魔法变量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "# 获取当前文件所在目录的路径\n",
    "current_dir = os.path.dirname(__file__)\n",
    "file_path = os.path.join(current_dir, 'content.txt')\n",
    "# 打开文件并读取内容\n",
    "with open(file_path, 'r', encoding='utf-8') as file:\n",
    "    content = file.read()  # 将文件内容存储到变量 content 中\n",
    "\n",
    "\n",
    "def function_A():\n",
    "    print(\"This is function A\",content)\n",
    "\n",
    "function_A()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "一个具体的例子说明`-m`参数的意义\n",
    "\n",
    "```shell\n",
    "(base) root@e3f188fe77b5:~/MyCode/trashbin/module/test_python_package# python package/main.py\n",
    "sys.path: ['/root/MyCode/trashbin/module/test_python_package/package', '/opt/anaconda3/lib/python37.zip', '/opt/anaconda3/lib/python3.7', '/opt/anaconda3/lib/python3.7/lib-dynload', '/opt/anaconda3/lib/python3.7/site-packages']\n",
    "__name__: __main__\n",
    "__package__: None\n",
    "__file__: package/main.py\n",
    "(base) root@e3f188fe77b5:~/MyCode/trashbin/module/test_python_package# python -m package.main\n",
    "sys.path: ['/root/MyCode/trashbin/module/test_python_package', '/opt/anaconda3/lib/python37.zip', '/opt/anaconda3/lib/python3.7', '/opt/anaconda3/lib/python3.7/lib-dynload', '/opt/anaconda3/lib/python3.7/site-packages']\n",
    "__name__: __main__\n",
    "__package__: package\n",
    "__file__: /root/MyCode/trashbin/module/test_python_package/package/main.py\n",
    "```\n",
    "测试的办法是"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "print(\"sys.path:\", sys.path)\n",
    "\n",
    "print(f\"__name__: {__name__}\")\n",
    "print(f\"__package__: {__package__}\")\n",
    "print(f\"__file__: {__file__}\")"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
